package com.bml.architect.spring.convert;

import com.bml.architect.spring.convert.jdk.StringToUserPropertyEditor;
import com.bml.architect.spring.convert.spring.StringToUserConvert;
import com.bml.architect.spring.service.User;
import org.springframework.beans.SimpleTypeConverter;
import org.springframework.core.convert.support.DefaultConversionService;

/**
 * TypeConverter整合了PropertyEditor和ConversionService的功能，是Spring内部用的
 */
public class Test {

    public static void main(String[] args) {
        SimpleTypeConverter converter = new SimpleTypeConverter();
        //注入JDK自带的类型转换器
        converter.registerCustomEditor(User.class,new StringToUserPropertyEditor());

        //spring内部的类型转换器
        DefaultConversionService conversionService = new DefaultConversionService();
        conversionService.addConverter(new StringToUserConvert());
        converter.setConversionService(conversionService);


        User user = converter.convertIfNecessary("11111", User.class);
        System.out.println(user);
    }
}
